{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Populating the interactive namespace from numpy and matplotlib\n"
     ]
    }
   ],
   "source": [
    "%pylab inline\n",
    "from ipywidgets import *\n",
    "from IPython.display import display\n",
    "from geoscilabs.em.Reflection import PowerReflection"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Reflection and Refraction of plane waves"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Purpose\n",
    "\n",
    "Electromagnetic waves are reflected and refracted at a plane interface separating media of different electrical properties. Essential items to understand here are:\n",
    "\n",
    "- What are TE and TM modes for reflection, and refraction\n",
    "- How reflection and refraction changes due to incidient angle and electrical parameters\n",
    "- Total reflection\n",
    "- Brewster angle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Set up\n",
    "\n",
    "A plane wave is reflected and refracted at a plane wave interface. Here $\\mathbf{k}$ is wave propagation consant, which is a vector. We consider two different modes:\n",
    "\n",
    "- Transverse electric (TE): No vertical electric field \n",
    "- Transverse magnetic (TM): No vertical magnetic field \n",
    "\n",
    "<img src=\"http://em.geosci.xyz/_images/snellslaw_setup.png\" width=500 px></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## TE mode\n",
    "\n",
    "Electric field ($\\mathbf{E}$) is transverse to the plane of incidence (No vertical electric field)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"http://em.geosci.xyz/_images/fresnel_setup_TE.png\" width=500 px></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## TM mode\n",
    "\n",
    "Magnetic field ($\\mathbf{H}$) is transverse to the plane of incidence (No vertical electric field)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"http://em.geosci.xyz/_images/fresnel_setup_TM.png\" width=500 px></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Reflection and Transmision app\n",
    "\n",
    "## Parameters\n",
    "\n",
    "- $\\sigma_1$: Conductivity of the first layer (S/m)\n",
    "\n",
    "- $\\sigma_2$: Conductivity of the first layer (S/m)\n",
    "\n",
    "- $f$ (Hz): Frequency (Hz)\n",
    "\n",
    "- Type: \n",
    "\n",
    "    - Reflection: Transmission power as a function of incident angle    \n",
    "    - Transmission: Transmission power as a function of incident angle    \n",
    "    - Angle: relationship between $\\theta_i$ and $\\theta_t$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "49836391b8334e778a8037abbbf2669a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatText(value=0.0, description='$\\\\sigma_1$'), FloatText(value=0.01, description='$\\\\s…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "Q = interact(PowerReflection\n",
    "        , sig1 = FloatText(value=0., description=\"$\\sigma_1$\")\n",
    "        , sig2 = FloatText(value=1e-2, description=\"$\\sigma_2$\")\n",
    "        , f = FloatText(value=6e5, description=\"$f$ (Hz)\")\n",
    "        , Type = ToggleButtons(options=[\"Reflection\", \"Transmission\", \"Angle\"])\n",
    "        )"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  },
  "widgets": {
   "state": {
    "8d55e68de241408dad272f61b93ee653": {
     "views": [
      {
       "cell_index": 9
      }
     ]
    }
   },
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
